// *** LICENSE HEADER ***
// Filename: ./particlesystem.h
// This file is part of Nodewarz 0.1
// Nodewarz is a 3d OpenGL strategy game
// Copyright (C) 2007 CZestmyr
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// *** END LICENSE HEADER ***
#ifndef NODEWARS_PARTICLE_SYSTEM_H
#define NODEWARS_PARTICLE_SYSTEM_H

#include <GL/gl.h>
#include <cstring>
#include "particleemitter.h"
#include "imagefunctions.h"

class particleEmitter;

//Class holding all the game particle emitters
class particleSystem {
    public:
        particleSystem();
        ~particleSystem();

        //Create a new particle emitter of predefined type t
        int CreateEmitter(float x, float y, float z, int textureHandle,
                          int t = 0, float otherX = 0.0f, float otherY = 0.0f, float otherZ = 0.0f);
        //Remove a particle emitter
        void RemoveEmitter(int handle);

        //Load/unload particle textures
        void LoadParticleTexture(int textureHandle, const char* filename);
        void UnloadParticleTexture(int textureHandle);

        //Update the particle system
        void Update(int dt);
        //Draw the particle emitters
        void Draw();
    private:
        //Reallocate particle emitter buffer
        void ReallocateBuffer();

        //Particle emitter buffer, fill and size
        particleEmitter** emitters;
        int emitterNumber;
        int emitterBufferSize;

        //Texture handles
        GLuint textures[16];

        //Freed particle emitter handles
        int* freedHandles;
        int freedHandleNumber;
};

#endif
